Spring Boot 修改tomcat端口

您所在的位置:网站首页 axure cloud如何修改启动端口 Spring Boot 修改tomcat端口

Spring Boot 修改tomcat端口

2024-07-14 19:36| 来源: 网络整理| 查看: 265

在spring boot的web 工程中,可以使用内置的web container、有时需要修改服务端口。

方法一:通过配置类和@Configuration注解来完成 import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class MyConfiguration { @Value("${tomcatport:8090}") private int port; @Bean public EmbeddedServletContainerFactory servletContainer(){ return new TomcatEmbeddedServletContainerFactory(this.port); } }

使用@Value注解,为tomcatport赋予8090的端口。 可以进入TomcatEmbeddedServletContainerFactory类查看实现的处理。

方法二:在应用的application.properties或者yml配置文件中,添加配置项 #指定web 的 contex path server.contextPath=/myapp #指定服务端口 server.port=8080


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3